<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #app {
            border: 1px solid green;
            width: 300px;
            padding: 50px 0;
        }
        
        p {
            width: 300px;
            text-align: center;
            font-size: 25px;
        }
        
        .box div {
            width: 80px;
            line-height: 40px;
            margin: 0 auto;
            color: #fff;
            background-color: #3883e9;
        }
        
        .parent {
            text-align: center;
        }
    </style>
</head>

<body>
    <div id="app">
        <parent></parent>
    </div>
    <template id="pT">
        <div class="parent">
            {{num}}
            <child @jia="getnum"></child>
        </div>
    </template>
    <template id="cT">
        <div  class="box">
            <div @click="add()">点击计数</div>
        </div>
    </template>
</body>

<script src="js/vue.js"></script>
<script>
    Vue.component("parent", {
        template: "#pT",
        data() {
            return {
                num: 0
            }
        },
        methods: {
            getnum(val) {
                console.log(val);
                this.num = val
            }
        },
        components: {
            child: {
                data() {
                    return {
                        cnum: 0
                    }
                },
                template: "#cT",
                methods: {
                    add() {
                        this.cnum++
                            this.$emit("jia", this.cnum)
                    }
                }
            }
        }
    })
    let vm = new Vue({
        el: "#app",
        data: {},
    })
</script>

</html>